package com.renbang.action.devoloper;


import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.renbang.model.common.AjaxResult;
import com.renbang.model.common.Page;
import com.renbang.model.sys.SysBtn;
import com.renbang.model.sys.SysFun;
import com.renbang.service.sys.SysBtnServiceImp;
@Controller
@RequestMapping(value = "developer/btn")
public class SysBtnAction{
	@Autowired
	SysBtnServiceImp sysBtnServiceImp;
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(HttpServletRequest request,SysBtn sysbtn,Page page) {
		Integer count = sysBtnServiceImp.findTotal(sysbtn);
		return new AjaxResult(AjaxResult.STATUS_OK, page.getCurrpage()+"",null ,sysBtnServiceImp.findInPage(sysbtn,page), count);
	}
	
	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(SysBtn btn) {
		System.out.println(btn);
		if (btn.getBtnId() != null) {
			sysBtnServiceImp.modify(btn);
			return new AjaxResult(AjaxResult.STATUS_OK, null, "修改成功");
		} else {
			sysBtnServiceImp.add(btn);
			 return new AjaxResult(AjaxResult.STATUS_OK, null, "增加成功");
		}
	}
	
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(Integer id) {
		Integer num = sysBtnServiceImp.removeById(id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "成功删除"+num+"条");
	}
	
	@RequestMapping(value = "/editForm")
	public String editForm(Integer id, HttpServletRequest request) {
		SysBtn btn;
		if (id != null) {
			btn = sysBtnServiceImp.findById(id);
			request.setAttribute("obj", btn);
		}
		return "developer/btn-form";
	}
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		Integer count = sysBtnServiceImp.findTotal(null);
		return new AjaxResult(AjaxResult.STATUS_OK, null ,sysBtnServiceImp.findByModel(null), count);
	}
	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Integer btnId) {
		SysBtn sysBtn = sysBtnServiceImp.findById(btnId);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(sysBtn), 0);
	}
}
